package LawsonTransformJava.pgm;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Report extends FileWriter {
	protected File fOutput = null;
	
	protected String pgmName = "XX999";
	protected String rptTitle = "Transformation Report";
	protected String timeStamp;
	protected String runStart = null;

	//Report Record Counters
	protected int recReadCnt = 0;
	protected int recWrittenCnt = 0;
	protected int recErrorCnt = 0;
	protected int recSkippedCnt = 0;

	//Set the Date Format for output
	protected static SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

	public Report(File fOutput, Date runStart) throws IOException {
		super(fOutput);
		this.fOutput = fOutput;
		this.runStart = df.format(runStart);
		
	}

	public void addReadCnt() {
		recReadCnt = recReadCnt + 1;
	}
	
	public void resetReadCnt() {
		recReadCnt = 0;
	}

	public void addWrittenCnt() {
		recWrittenCnt = recWrittenCnt + 1;
	}

	public void resetWrittenCnt() {
		recWrittenCnt = 0;
	}
	
	public void addErrorCnt() {
		recErrorCnt = recErrorCnt + 1;
	}

	public void resetErrorCnt() {
		recErrorCnt = 0;
	}
	
	public void addSkippedCnt() {
		recSkippedCnt = recSkippedCnt + 1;
	}

	public void resetSkippedCnt() {
		recSkippedCnt = 0;
	}
	
	public void setPgmName(String pgmName) {
		this.pgmName = pgmName;
	}
	
	public void setRptTitle (String rptTitle) {
		this.rptTitle = rptTitle;
	}
	
	public String getName() {
		return fOutput.getName();
	}
	
	public static SimpleDateFormat getDateFormat() {
		return df;
	}
		
	public void writeRecordCounts(int tblCount) throws IOException {
		write(writeRptHeading() + "\n");
		write("\n\n\n\n\n");
		write(" Record Count    : " + tblCount + "\n");		
		write(" Records Read    : " + recReadCnt + "\n");
		write(" Records Written : " + recWrittenCnt + "\n");
		write(" Records Skipped : " + recSkippedCnt + "\n");
		write(" Records in Error: " + recErrorCnt + "\n");
		write("\n\n\n\n\n\n\n\n\n");
		//Write timestamp to output file
		write(fOutput.getName() + " Start    " + runStart + "\n");
		//Write timestamp to output file
		write(fOutput.getName() + " Complete " + df.format(new Date()) + "\n");
		write(writeRptFooter());
	}

	public String writeRptHeading() {
		return
				pgmName +
				"                                            " +
				rptTitle +
				"                                        " +
				df.format(new Date());
	}	

	public String writeRptFooter() {
		return
				"\n\n\n                                                    Report Complete"
			;
	}	
}
